/*
 * @Author: Lin Hongwei
 * @Date: 2022-10-30 15:31:59
 * @LastEditTime: 2022-11-05 11:08:59
 * @LastEditors: Lin Hongwei
 * @email: 1365755396@qq.com
 * @CSDN: https://blog.csdn.net/weixin_45429409
 * @Description: 任务
 */
const CRUDService = require('.');
const { query } = require('../utils/db');
class TaskService extends CRUDService {
  constructor() {
    super('task')
  }
  queryTask = async (params) => {

    let sql = `select * from ${this.tableName} `;
    let values = Object.assign({}, params);
    if (params) {
      let keys = Object.keys(params);
      let nameIndex = keys.findIndex(item => item == 'name');
      values = Object.values(params);
      let str = ' ';
      if (nameIndex != -1) {
        keys.splice(nameIndex, 1);
        values.splice(nameIndex, 1);
        str += ` name like '%${params.name}%' and `
      }
      str += keys.join(' = ? and ');
      // str = str.replace(/name = ?/,`name like '%?%'`)

      str.length && (sql = `${sql} where ${str} = ? `);
    }
    sql += ` order by kanbanId,sort `;
    return query(sql, values || {});
  }
  /**
   * @description: 跨看板移动
   */
  sortCross = async (params) => {
    return query('call task_cross_sort_procedure(?,?,?)', params)
  }
}

module.exports = new TaskService()